package com.ruiysoft.controller.sys.api.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruiysoft.constant.DesignTypeConst;
import com.ruiysoft.constant.IdentityConst;
import com.ruiysoft.controller.integral.vo.IntegralRechargeVo;
import com.ruiysoft.controller.sys.dto.ShopDesignDto;
import com.ruiysoft.controller.sys.dto.ShopDistributionDto;
import com.ruiysoft.controller.sys.dto.ShopDto;
import com.ruiysoft.controller.sys.dto.UserDto;
import com.ruiysoft.controller.sys.res.BrowsedShopResponse;
import com.ruiysoft.controller.sys.res.PreorderResponse;
import com.ruiysoft.controller.sys.res.SlideModelResponse;
import com.ruiysoft.entity.mdse.MerchandiseSku;
import com.ruiysoft.entity.order.OrderRelationCommission;
import com.ruiysoft.entity.sys.SysMicroShop;
import com.ruiysoft.entity.sys.SysShopDesign;
import com.ruiysoft.entity.sys.SysShopDistribution;
import com.ruiysoft.entity.sys.SysShopModuleRelation;
import com.ruiysoft.entity.sys.SysShopPersonnel;
import com.ruiysoft.entity.sys.SysShopPersonnelRelation;
import com.ruiysoft.entity.sys.SysShopPrice;
import com.ruiysoft.entity.sys.SysTransactionRecord;
import com.ruiysoft.entity.sys.SysUser;
import com.ruiysoft.entity.sys.SysUserShopRelation;
import com.ruiysoft.mapper.mdse.MerchandiseSkuMapper;
import com.ruiysoft.mapper.sys.SysShopPersonnelMapper;
import com.ruiysoft.service.integral.IIntegralService;
import com.ruiysoft.service.order.IOrderRelationCommissionService;
import com.ruiysoft.service.sys.ISysMicroShopService;
import com.ruiysoft.service.sys.ISysShopDesignService;
import com.ruiysoft.service.sys.ISysShopDistributionService;
import com.ruiysoft.service.sys.ISysShopModuleRelationService;
import com.ruiysoft.service.sys.ISysShopPersonnelRelationService;
import com.ruiysoft.service.sys.ISysShopPersonnelService;
import com.ruiysoft.service.sys.ISysShopPriceService;
import com.ruiysoft.service.sys.ISysTransactionRecordService;
import com.ruiysoft.service.sys.ISysUserService;
import com.ruiysoft.service.sys.ISysUserShopRelationService;
import com.ruiysoft.service.sys.clent.LoginContextUtil;
import com.ruiysoft.service.sys.redis.IRedisSysUserService;
import com.ruiysoft.service.wechat.IWeChatService;
import com.ruiysoft.util.CodeGenerator;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by 化增光 on 2018/11/1.
 */
@Service
public class MicroprogramApiService {

    @Resource
    ISysUserService iSysUserService;

    @Resource
    ISysMicroShopService iSysMicroShopService;

    @Resource
    ISysShopDesignService iSysShopDesignService;

    @Resource
    ISysShopDistributionService iSysShopDistributionService;

    @Resource
    IRedisSysUserService iRedisSysUserService;

    @Resource
    IWeChatService iWeChatService;

    @Resource
    ISysShopPersonnelService iSysShopPersonnelService;

    @Resource
    ISysShopPersonnelRelationService iSysShopPersonnelRelationService;

    @Resource
    ISysTransactionRecordService iSysTransactionRecordService;

    @Resource
    ISysShopPriceService iSysShopPriceService;

    @Resource
    ISysUserShopRelationService iSysUserShopRelationService;

    @Autowired
    ISysShopModuleRelationService iSysShopModuleRelationService;

    @Autowired
    SysShopPersonnelMapper sysShopPersonnelMapper;

    @Autowired
    MerchandiseSkuMapper merchandiseSkuMapper;
    @Autowired
    IOrderRelationCommissionService orderRelationCommissionService;

    /*@Autowired
    @Qualifier("DefaultBCryptPasswordEncoder")
    BCryptPasswordEncoder passwordEncoder;*/

//    @Resource
//    IRedisSysMicroShopService iRedisSysMicroShopService;

    public List<SysShopPersonnel> getShopVisitorList() {
        Long shopId = LoginContextUtil.instance().getEntryMicroShop().getId();
        return sysShopPersonnelMapper.selectVisitorList(shopId);
    }

    @Transactional
    public Long register(@Valid UserDto user, int loginType) {

        List<SysUser> list = iSysUserService.list(new QueryWrapper<SysUser>().eq("user_name", user.getUsername()).or().eq("mobile", user.getMobile()));

        if (list != null && list.size() > 0) {
            throw new IllegalArgumentException("用户名或手机号已存在!");
        }
        SysShopPersonnel personnel = LoginContextUtil.instance().getEntryUser().getPersonnel();

        //初始化店铺
        SysMicroShop sysMicroShop = this.initializeSysMicroShop();
        this.initializeSysUserInfo(personnel.getId(), sysMicroShop.getId(), user);
        return sysMicroShop.getId();
        //this.chooseBrowsedShop(loginType,sysUser.getId(),personnel.getId(), sysMicroShop.getId());
    }

//    private void updateSysShopPersonnelIdentity(Long shopId, Long personnelId, Integer shopkeeper) {
//        iSysShopPersonnelRelationService.saveOrUpdate(shopId,personnelId,shopkeeper);
//    }

    private SysMicroShop initializeSysMicroShop() {
        //插入店铺
        SysMicroShop sysMicroShop = new SysMicroShop()
                .setCreateTime(new Date())
                .setUpdateTime(new Date())
                .setEnabled(true)
                .setExpiryTime(DateUtils.addDays(new Date(), 30))
                .setDeleteFlag(false)
                .setVersion(0);
        iSysMicroShopService.save(sysMicroShop);
        return sysMicroShop;
    }

    private SysUser initializeSysUserInfo(Long personnelId, Long shopId, @Valid UserDto user) {
        SysUser sysUser = new SysUser()
                .setPersonnelId(personnelId)
                .setUserName(user.getUsername())
                .setPassword("$2a$10$nwlALcnFf3dcT1XdoGNL8uNjgCATKI0tOzG7ue4gl7fJz1uXCTwDa")
                .setRealName(user.getRealName())
                .setMobile(user.getMobile())
                .setEnabled(true)
                .setDeleteFlag(false)
                .setCreateTime(new Date())
                .setUpdateTime(new Date())
                .setVersion(0);

        iSysUserService.save(sysUser);
        iSysShopPersonnelRelationService.insertIgnore(new SysShopPersonnelRelation().setShopId(shopId).setPersonnelId(personnelId));
        iSysUserShopRelationService.insertIgnore(new SysUserShopRelation().setShopId(shopId).setUserId(sysUser.getId()));
        return sysUser;
    }

//    public Long getCurrentLoginOnShopId() {
//        UserInfo userInfo = LoginContextUtil.instance().getWecChatUserInfo();
//        return iRedisSysUserService.getCurrentLoginOnShopId(userInfo.getPersonnelId());
//    }

//    public String getCurrentLoginOnUsername(){
//        UserInfo userInfo = LoginContextUtil.instance().getWecChatUserInfo();
//        return userInfo.getOpenid();
//    }

    public List<SlideModelResponse> getSlideModelByShopId(Long shopId) {
        Assert.notNull(shopId, "shop id is null");
        //1轮播图
        List<SysShopDesign> r = iSysShopDesignService.list(new QueryWrapper<SysShopDesign>().eq("shop_id", shopId).eq("design_type", DesignTypeConst.SLIDE_MODEL));
        List<SlideModelResponse> responses = new ArrayList<>();
        r.stream().forEach(e -> {
            responses.add(new SlideModelResponse().imgUrl(e.getImgUrl()).linkType(e.getLinkType()).linkUrl(e.getLinkUrl()));
        });
        return responses;
    }

//    public UserResponse getLoginOnUser(Long shopId, String openid) {
//        Assert.notNull(shopId,"shop id is null");
//        Assert.notNull(openid,"openid is null");
//        SysShopPersonnel personnel = iSysShopPersonnelService.selectOne(new EntityWrapper<SysShopPersonnel>().eq("shop_id",shopId).eq("openid",openid));
//        SysShopPersonnelRelation relation = iSysShopPersonnelRelationService.selectOne(new EntityWrapper<SysShopPersonnelRelation>().eq("shop_id",shopId).eq("openid",openid));
//        return new UserResponse().identity(relation.getIdentityType()).mobile(personnel.getMobile());
//    }

//    public ShopResponse getLoginOnShop(Long shopId) {
//        SysMicroShop shop = iSysMicroShopService.selectById(shopId);
//        return new ShopResponse().shopName(shop.getShopName()).shopImg(shop.getShopImg()).brandIntroduction(shop.getBrandIntroduction()).officialWebsite(shop.getOfficialWebsite()).telephone(shop.getTelephone()).shopAddress(shop.getShopAddress());
//    }

    public List<BrowsedShopResponse> getBrowsedShops(Long personnelId) {
        long start = System.currentTimeMillis();
        Assert.notNull(personnelId, "personnelId is null");
        List<SysShopPersonnelRelation> r = iSysShopPersonnelRelationService.list(new QueryWrapper<SysShopPersonnelRelation>().eq("personnel_id", personnelId).orderBy(false,false,"create_time"));
        //System.out.println("獲取到SysShopPersonnelRelation:" + JSON.toJSONString(r));
        SysUser user = getSysUserByPersonnelId(personnelId);
        //System.out.println("獲取到user" + user);
        List<SysUserShopRelation> userShopRelations = new ArrayList<>();
        if (null != user) {
            userShopRelations = iSysUserShopRelationService.list(new QueryWrapper<SysUserShopRelation>().eq("user_id", user.getId()));
        }

        //System.out.println("獲取到SysUserShopRelation:" + JSON.toJSONString(userShopRelations));
        List<BrowsedShopResponse> responses = new ArrayList<>();
        r.stream().forEach(e -> {
            SysMicroShop microShop = iSysMicroShopService.selectSysMicroShopById(e.getShopId());
            if(microShop != null)
                responses.add(new BrowsedShopResponse()
                    .id(microShop.getId()).shopName(microShop.getShopName()).setIdentityType(IdentityConst.ORDINARY_USER).setImgUrl(microShop.getShopImg()));
        });

        //System.out.println("獲取到BrowsedShopResponse:" + JSON.toJSONString(responses));
        userShopRelations.stream().forEach(e -> {
            responses.stream().forEach(s -> {
                if (e.getShopId().longValue() == s.getId().longValue()) {
                    s.setIdentityType(IdentityConst.SHOPKEEPER);
                }
            });
        });

        System.out.println("獲取到BrowsedShopResponse:" + JSON.toJSONString(responses));
        long end = System.currentTimeMillis();
        System.out.println("总共用时:" + (end - start));
        return responses;
    }

//    public ShopResponse getShopById(Long shopId) {
//        Assert.notNull(shopId,"shop id is null");
//        SysMicroShop shop = iSysMicroShopService.selectById(shopId);
//        if (null == shop){
//            //返回异常信息
//            return null;
//        }
//        return new ShopResponse().shopName(shop.getShopName())
//                .shopImg(shop.getShopImg())
//                .brandIntroduction(shop.getBrandIntroduction())
//                .officialWebsite(shop.getOfficialWebsite())
//                .telephone(shop.getTelephone())
//                .shopAddress(shop.getShopAddress())
//                .setVipLeve(shop.getVipLevel())
//                .setExpiryTime(shop.getExpiryTime());
//    }

    @Transactional
    public void updateShopById(Long shopId, @Valid ShopDto shop) {
        Assert.notNull(shopId, "shop id is null");
        SysMicroShop sysMicroShop = iSysMicroShopService.selectSysMicroShopById(shopId);
        if (null == sysMicroShop) {
            //返回异常信息
            Assert.notNull(sysMicroShop, "SysMicroShop is null");
        }
        sysMicroShop.setShopName(shop.getShopName())
                .setShopImg(shop.getShopImg())
                .setShopAddress(shop.getShopAddress())
                .setBrandIntroduction(shop.getBrandIntroduction())
                .setOfficialWebsite(shop.getOfficialWebsite())
                .setTelephone(shop.getTelephone());
        iSysMicroShopService.updateById(sysMicroShop);
        iSysMicroShopService.clearSysMicroShopById(sysMicroShop.getId());
    }

    public void deleteShopDesignById(Long shopId, Long id) {
        Assert.notNull(shopId, "shop id is null");
        Assert.notNull(id, "id is null");
        iSysShopDesignService.remove(new QueryWrapper<SysShopDesign>().eq("shop_id", shopId).eq("id", id));
    }

    public List<ShopDesignDto> getShopDesignByShopId(Long shopId) {
        Assert.notNull(shopId, "shop id is null");
        List<SysShopDesign> r = iSysShopDesignService.list(new QueryWrapper<SysShopDesign>().eq("shop_id", shopId));
        List<ShopDesignDto> rd = new ArrayList<>();
        r.stream().forEach(e -> {
            ShopDesignDto shopDesignDto = new ShopDesignDto()
                    .id(e.getId())
                    .linkUrl(e.getLinkUrl())
                    .designType(e.getDesignType())
                    .linkType(e.getLinkType())
                    .imgUrl(e.getImgUrl());

            int skuId = Integer.parseInt(e.getLinkUrl());
            MerchandiseSku merchandiseSku = merchandiseSkuMapper.selectById(skuId);

            if(merchandiseSku != null)
                shopDesignDto.setGoodsName(merchandiseSku.getMerchandiseName());

            rd.add(shopDesignDto);
        });
        return rd;
    }

    public ShopDesignDto getShopDesignById(Long shopId, Long id) {
        Assert.notNull(shopId, "shop id is null");
        Assert.notNull(id, "id is null");
        SysShopDesign sysShopDesign = iSysShopDesignService.getOne(new QueryWrapper<SysShopDesign>().eq("shop_id", shopId).eq("id", id));
        return new ShopDesignDto().id(sysShopDesign.getId()).designType(sysShopDesign.getDesignType()).imgUrl(sysShopDesign.getImgUrl()).linkUrl(sysShopDesign.getLinkUrl());
    }

    public ShopDistributionDto getShopDistributionByShopId(Long shopId) {
        Assert.notNull(shopId, "shop id is null");
        SysShopDistribution sysShopDistribution = iSysShopDistributionService.getOne(new QueryWrapper<SysShopDistribution>().eq("shop_id", shopId).orderBy(false,false,"create_time").last("limit 1"));
        if (null == sysShopDistribution) {
            return null;
        }
        return new ShopDistributionDto().firstRatio(sysShopDistribution.getFirstRatio()).secondRatio(sysShopDistribution.getSecondRatio()).minimumAmount(sysShopDistribution.getMinimumAmount());
    }

    public List<SysShopDistribution> getShopDistributionListByShopId(Long shopId) {
        Assert.notNull(shopId, "shop id is null");
        List<SysShopDistribution> sysShopDistribution = iSysShopDistributionService.list(new QueryWrapper<SysShopDistribution>().eq("shop_id", shopId).orderBy(false,false,"create_time"));
        if (null == sysShopDistribution) {
            return null;
        }
        return sysShopDistribution;
    }

    public Page<SysShopPersonnel> getPersonnelByParentId(@NotNull @Valid Long shopId,@NotNull @Valid Long userId, @NotNull @Valid Integer pageStart, @NotNull @Valid Integer pageSize) {
        return iSysShopPersonnelService.getPersonnelByParentId(pageStart, pageSize, shopId,userId);
    }

    public void updateShopDesignById(Long shopId, @Valid ShopDesignDto shopDesign) {
        Assert.notNull(shopId, "shop id is null");
        SysShopDesign sysShopDesign = iSysShopDesignService.getOne(new QueryWrapper<SysShopDesign>().eq("shop_id", shopId).eq("id", shopDesign.getId()));
        Assert.notNull(sysShopDesign, "SysShopDesign is null");
        sysShopDesign.setDesignType(shopDesign.getDesignType());
        sysShopDesign.setImgUrl(shopDesign.getImgUrl());
        sysShopDesign.setLinkType(shopDesign.getLinkType());
        sysShopDesign.setLinkUrl(shopDesign.getLinkUrl());
        sysShopDesign.setUpdateTime(new Date());
        iSysShopDesignService.updateById(sysShopDesign);
    }

    public void updateShopDistribution(Long shopId, @Valid SysShopDistribution distribution) {
        Assert.notNull(shopId, "shop id is null");
        iSysShopDistributionService.update(new UpdateWrapper<SysShopDistribution>().set("defaultFlag","0").eq("shop_id",shopId));
        SysShopDistribution sysShopDistribution = new SysShopDistribution().setId(distribution.getId())
                .setFirstRatio(distribution.getFirstRatio())
                .setShopId(shopId)
                .setSecondRatio(distribution.getSecondRatio())
                .setMinimumAmount(distribution.getMinimumAmount())
                .setCreateTime(distribution.getId()==null ? new Date():distribution.getCreateTime())
                .setUpdateTime(new Date()).setName(distribution.getName()).setDefaultFlag(distribution.getDefaultFlag())
                .setEnabled(distribution.getId()==null ? true:distribution.getEnabled())
                .setVersion(distribution.getId()==null ? 0:distribution.getVersion()+1);
        iSysShopDistributionService.saveOrUpdate(sysShopDistribution);
    }

    public void chooseBrowsedShop(int loginType, Long userId, Long personnelId, @Valid Long shopId) {
        Assert.notNull(shopId, "shop id is null");
        iRedisSysUserService.setCurrentLoginShop(loginType, userId, personnelId, shopId);
    }

    public PreorderResponse preorder(Long shopId, Long personnelId, Integer num, BigDecimal price) {

        SysTransactionRecord sysTransactionRecord = new SysTransactionRecord()
                .setTransactionNo(CodeGenerator.INSTANCE.genOrderNo("VIP", null))
                .setAmount(price)
                .setCreateTime(new Date())
                .setShopId(shopId)
                .setPersonnelId(personnelId)
                .setPurchaseTime(num)
                .setState(0);
        iSysTransactionRecordService.save(sysTransactionRecord);

        return new PreorderResponse().orderNo(sysTransactionRecord.getTransactionNo());
    }

    public static void main(String[] args) {
        System.out.println(CodeGenerator.INSTANCE.genOrderNo("VIP", null));
    }

    public void addShopDesign(Long shopId, @Valid ShopDesignDto shopDesign) {
        SysShopDesign sysShopDesign = new SysShopDesign()
                .setDesignType(shopDesign.getDesignType())
                .setShopId(shopId)
                .setImgUrl(shopDesign.getImgUrl())
                .setLinkType(shopDesign.getLinkType())
                .setLinkUrl(shopDesign.getLinkUrl())
                .setCreateTime(new Date())
                .setUpdateTime(new Date())
                .setDeleteFlag(false)
                .setVersion(0);
        iSysShopDesignService.save(sysShopDesign);
    }

    @Transactional
    public void updatePersonnelById(SysShopPersonnel personnel) {
        iSysShopPersonnelService.updateById(personnel);
        iRedisSysUserService.clearSysShopPersonnelById(personnel.getId());
    }

    public Page<SysShopPersonnel> getShopPersonnel(@NotNull @Valid Long shopId, @NotNull @Valid Integer pageStart, @NotNull @Valid Integer pageSize) {
        return iSysShopPersonnelService.selectPersonnelList(pageStart, pageSize, shopId);
    }

    public Page<SysShopPersonnel> selectPersonnelRalationList(@NotNull @Valid Long shopId, @NotNull @Valid Integer pageStart, @NotNull @Valid Integer pageSize) {
        return iSysShopPersonnelService.selectPersonnelRalationList(pageStart, pageSize, shopId);
    }

    public List<SysShopPrice> getSysShopPrice() {
        return iSysShopPriceService.list(new QueryWrapper<SysShopPrice>());
    }

    public SysShopPrice getSysShopPriceByNum(Integer time) {
        return iSysShopPriceService.getOne(new QueryWrapper<SysShopPrice>().eq("num", time));
    }

    public void delBrowsedShop(Long personnelId, @Valid Long shopId) {
        Assert.notNull(personnelId, "personnelId id is null");
        Assert.notNull(shopId, "shop id is null");
        iSysShopPersonnelRelationService.remove(new QueryWrapper<SysShopPersonnelRelation>().eq("personnel_id", personnelId).eq("shop_id", shopId));

    }

    public SysTransactionRecord getSysTransactionRecord(String orderNo) {
        return iSysTransactionRecordService.getOne(new QueryWrapper<SysTransactionRecord>().eq("transaction_no", orderNo));
    }

    public SysUser getSysUserByPersonnelId(Long personnelId) {
        return iRedisSysUserService.selectSysUserByPersonnelId(personnelId);
    }

    public SysUserShopRelation getSysUserShopRelationByUserIdAndShopId(Long userId, Long shopId) {
        return iSysUserShopRelationService.getOne(new QueryWrapper<SysUserShopRelation>().eq("user_id", userId).eq("shop_id", shopId));
    }

    public SysShopPersonnel getShopPersonnelById(Long id) {
        return iSysShopPersonnelService.getById(id);
    }

    public List<SysShopModuleRelation> getShopModuleByShopId(Long id) {
        return iSysShopModuleRelationService.selectShopModuleByShopId(id);
    }

    public void updateShopPersonnelRelation(List<SysShopPersonnelRelation> relations) {
        iSysShopPersonnelRelationService.updateShopPersonnelRelation(relations);
    }
    public void setDistributionRelation(SysShopPersonnelRelation relation) {
        SysMicroShop microShop = LoginContextUtil.instance().getEntryMicroShop();
        SysShopPersonnel personnel = LoginContextUtil.instance().getEntryUser().getPersonnel();
        iSysShopPersonnelRelationService.setDistributionRelation(microShop.getId(),personnel.getId(),relation.getParentId());
    }

    public int deleteShopDistribution(Long id) {
       if(iSysShopDistributionService.removeById(id)){
           return 1;
       }
       return 0;
    }

    public SysShopDistribution getDistributionById(Long id) {
        return iSysShopDistributionService.getById(id);
    }

    @Transactional
    public void setDistributionIdToUser(SysShopPersonnelRelation relation) {
        SysMicroShop microShop = LoginContextUtil.instance().getEntryMicroShop();
        iSysShopPersonnelRelationService.update(new UpdateWrapper<SysShopPersonnelRelation>().set("distributionId",relation.getDistributionId()).eq("personnel_id",relation.getPersonnelId()).eq("shop_Id",microShop.getId()));
    }

    public SysShopDistribution getDistributionIdByUser(Long id, Long id1) {
        SysShopPersonnelRelation relation=iSysShopPersonnelRelationService.getOne(new QueryWrapper<SysShopPersonnelRelation>().eq("shop_id",id).eq("personnel_id",id1),false);
        if(relation!=null && relation.getDistributionId()!=0){
            return iSysShopDistributionService.getById(relation.getDistributionId());
        }
        return iSysShopDistributionService.getOne(new QueryWrapper<SysShopDistribution>().eq("shop_id",id).eq("defaultFlag",1).last("limit 1"));
    }

    public Page<SysShopPersonnel> getRelationCommissionList(@NotNull @Valid Long shopId, @NotNull @Valid Integer pageStart, @NotNull @Valid Integer pageSize) {
        return orderRelationCommissionService.getRelationCommissionList(pageStart, pageSize, shopId);
    }

    public Page getRelationCommissionByUserId(Long shopId, Long userId, Integer pageStart, Integer pageSize) {
        return orderRelationCommissionService.getRelationCommissionByUserId(pageStart, pageSize, shopId,userId);
    }
    public Page getRelationCommissionByBuyerId(Long shopId, Long userId, Integer pageStart, Integer pageSize, Long id) {
        return orderRelationCommissionService.getRelationCommissionByBuyerId(pageStart, pageSize, shopId,userId,id);
    }

    public boolean settleCommissionByIds(Long shopId, List<String> ids,String note) {
        boolean i=orderRelationCommissionService.update(new UpdateWrapper<OrderRelationCommission>().set("settleFlag",1).set("settleNode",note).set("settleDate",new Date()).in("id",ids));
    return i;
    }

    public Page getRelationCommissionDisByUserId(Long shopId, Long userId, Integer pageStart, Integer pageSize) {
        return orderRelationCommissionService.getRelationCommissionDisByUserId(pageStart, pageSize, shopId,userId);
    }

    public Page getCurrentDistributionerList(Long shopId, Long userId, Integer pageStart, Integer pageSize) {
        return orderRelationCommissionService.getCurrentDistributionerList(pageStart, pageSize, shopId,userId);
    }

//    public TokenResponse getAccessToken(Long shopId) {
//        Assert.notNull(shopId,"shop id is null");
//        String access_token = iWeChatService.getAccessToken();
//        SysMicroShop shop = iSysMicroShopService.selectById(shopId);
//        if (shop.customConfigure()){
//
//        }
//        return new TokenResponse().token(access_token);
//    }
}
